<?
session_start();
$_SESSION['hora']=time();  
if ($_GET["force_lang"]!="")
	$_SESSION["adm_lang"]=substr($_GET["force_lang"],0,3);

$admin_area=1;
$admin = 1;
$override=1;
require("../includes/common_admin_inc.php");
?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html><head>
<title><? echo LA_ADMIN_LOGIN_TITLE ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=x-user-defined" />
<link rel="stylesheet" href="../style/admin.css" type="text/css" />
<script type="text/javascript" src="http://<? echo $url ?>/javascript/common.js"></script>
</head>

<body>

<?
if ($set_demo)
{
	echo "<center><p><b><font color='red'>Important:</font></b><br />System is in demo-mode and some functionality
	involving banner-upload, deletion of ads, template editing etc. will not work</p></center>";
}
?>


<form method="post" action="login.php">
<table align="center" style="font-size:12px;">
<tr><td colspan="2" align="center"><img src="../layout_images/powered.gif" /><br /><br /></td></tr>

<?
echo "<tr><td colspan='2' align='center'>";
$lUsername=getParam("admin_username","");
$lPassword=getParam("admin_password","");
$lUsername=strToDb($lUsername);
$lPassword=strToDb($lPassword);

if (!empty($lUsername) && !empty($lPassword))
{
	$sql="select count(adm_id) as num from $adm_tbl";
	$res_count=q($sql);
	$row_c=mysql_fetch_array($res_count);
	$num_admins=$row_c["num"];
	
	
	// Create new admin user if admin table is empty
	if ($num_admins<1)
	{
		q("insert into $adm_tbl (adm_id,adm_name,adm_pass,adm_level) values (1,'admin',md5('admin'),0)");
		//q("alter table $stat_tbl modify visit DEFAULT 'null'");
	}
	$sql="select adm_id,adm_level,adm_name from $adm_tbl where adm_name='$lUsername' AND adm_pass=md5('$lPassword')";
	$res=q($sql);
	$row=mysql_fetch_array($res);
	
	
	if ($row["adm_id"]>0)
	{
		$lUserID=$row["adm_id"];
		$_SESSION["admin"]=$lUserID;
		$_SESSION["admin_level"]=$row["adm_level"];
		$_SESSION["admin_name"]=$row["adm_name"];
		if (!$row["adm_level"])
			$_SESSION["admin_level"]=1;
		
		//$sql="select ser_program_version from $service_tbl order by ser_id desc limit 1";
		//$r=q($sql);
		//$row_v=mysql_fetch_array($r);
		//$_SESSION["version"]=$row_v["ser_program_version"];
		redirect("index.php");
		
	}
	else 
	{
		echo "<p><font color='red'><b>".LA_ADMIN_WRONG_TITLE."</b></font><br>".LA_ADMIN_WRONG_DESCR."</p>";
	}
	
	
}
echo "<br /></td></tr>";
?>
<tr><td><? echo LA_ADMIN_LOGIN_USERNAME ?></td><td><input type="text" name="admin_username" id="admin_username" value="<? echo getParam("admin_username",""); ?>"></td></tr>
<tr><td><? echo LA_ADMIN_LOGIN_PASSWORD ?></td><td><input type="password" name="admin_password" value="<? echo getParam("admin_password",""); ?>"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="<? echo LA_ADMIN_LOGIN_BUTTON ?>"></td></tr>

</table>
</form>

<!--
<center>
<p><a href="?force_lang=nor"><img src="../layout_images/flags/no.gif" border="0" /></a>
<a href="?force_lang=eng"><img src="../layout_images/flags/us.gif" border="0" /></a>
<a href="?force_lang=eng"><img src="../layout_images/flags/gb.gif" border="0" /></a>
</p>
</center>
-->

<script language="javascript">
<!--
document.getElementById("admin_username").focus();
-->
</script>

</body>



</html>


